package cn.icanci.loopstack.ddk.common.utils;

import cn.icanci.loopstack.ddk.common.model.PageList;
import cn.icanci.loopstack.ddk.common.model.Paginator;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;

import com.google.common.collect.Lists;

/**
 * @author icanci
 * @since 1.0 Created in 2023/01/07 18:30
 */
public class PaginatorUtils<T> {
    private PaginatorUtils() {
    }

    /**
     * 返回PageList
     * 
     * @param ret 数据集合
     * @param currentPage 当前页
     * @param pageSize 当前页大小
     * @param total 总量
     * @param <T> T
     * @return 返回PageList<T>
     */
    public static <T> PageList<T> formatPaginator(List<T> ret, int currentPage, int pageSize, int total) {
        if (CollectionUtils.isEmpty(ret)) {
            return new PageList<T>(Lists.newArrayList(), new Paginator(total, pageSize, currentPage));
        }
        return new PageList<T>(ret, new Paginator(total, pageSize, currentPage));
    }
}
